package com.kkshop.domain.security;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.kkshop.domain.Persistent;

@Entity
@Table(name = "authorities")
public class Authority implements Persistent<String> {

    @Id
    private String username;

    @Basic
    private String authority;

    public Authority(String username, String authority) {
        this.setUsername(username);
        this.setAuthority(authority);
    }

    public Authority() {
    }

    public String getAuthority() {
        return authority;
    }

    public void setAuthority(String authority) {
        this.authority = authority;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

	public String getId() {
		return username;
	}

	public void setId(String id) {
		username = id;
	}

	public boolean equals(Object other) {
		if(!(other instanceof Authority)) {
			return false;
		}
		
		Authority that = (Authority) other;
		
		return new EqualsBuilder()
				.append(username, that.username)
				.append(authority, that.authority).isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder()
				.append(username)
				.append(authority).toHashCode();
	}

	public String toString() {
		return new ToStringBuilder(this)
				.append("username", username)
				.append("authority", authority).toString();
	}
}
